﻿using System;
using System.Collections.Generic;
using System.Text;
using HsTec.Mobile.Green.Util;
using System.Data;

namespace HsTec.Mobile.Green.BLL
{
    public class ReportTemplateEntitysBLL
    {
        public List<HsTec.Mobile.Green.Model.ReportTemplateEntitys> GetEntityListByID(int uid)
        {
            return this.GetEntityList("select * from vi_ReportTemplateEntitys where FieldParent=" + uid);
        }
        public List<HsTec.Mobile.Green.Model.ReportTemplateEntitys> GetEntityList(string strSql)
        {
            DataView dv = SQLHelper.ExecuteDataView(strSql);
            return DataTableToList(dv.Table);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.ReportTemplateEntitys> DataTableToList(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.ReportTemplateEntitys> modelList = new List<HsTec.Mobile.Green.Model.ReportTemplateEntitys>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.ReportTemplateEntitys model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.ReportTemplateEntitys();
                    if (dt.Rows[n]["RT_ID"].ToString() != "")
                    {
                        model.RT_ID = int.Parse(dt.Rows[n]["RT_ID"].ToString());
                    }
                    model.FieldName = dt.Rows[n]["FieldName"].ToString();
                    model.FieldAlias = dt.Rows[n]["FieldAlias"].ToString();
                    if (dt.Rows[n]["FieldType"].ToString() != "")
                    {
                        model.FieldType = int.Parse(dt.Rows[n]["FieldType"].ToString());
                    }
                    if (dt.Rows[n]["FieldSelect"].ToString() != "")
                    {
                        model.FieldSelect = int.Parse(dt.Rows[n]["FieldSelect"].ToString());
                    }
                    model.SelectContent = dt.Rows[n]["SelectContent"].ToString();
                    model.EecelCell = dt.Rows[n]["EecelCell"].ToString();
                    model.Remark = dt.Rows[n]["Remark"].ToString();
                    if (dt.Rows[n]["FieldParent"].ToString() != "")
                    {
                        model.FieldParent = int.Parse(dt.Rows[n]["FieldParent"].ToString());
                    }
                    if (dt.Rows[n]["FieldChildCount"].ToString() != "")
                    {
                        model.FieldChildCount = int.Parse(dt.Rows[n]["FieldChildCount"].ToString());
                    }
                    if (dt.Rows[n]["FieldNo"].ToString() != "")
                    {
                        model.FieldNo = int.Parse(dt.Rows[n]["FieldNo"].ToString());
                    }
                    model.FieldFormula = dt.Rows[n]["FieldFormula"].ToString();
                    if (dt.Rows[n]["FieldTemplate"].ToString() != "")
                    {
                        model.FieldTemplate = int.Parse(dt.Rows[n]["FieldTemplate"].ToString());
                    }
                    model.FieldTemplateName = dt.Rows[n]["FieldTemplateName"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}
